#include <iostream>
#include <thread>
#include <vector>
#include <unistd.h>
#include "RingQueue.hpp"

using namespace RingQueueModule;

void producer(RingQueue<int>& rq, int cnt)
{
    for (int i = 0; i < cnt; ++i)
    {
        rq.Equeue(i);
        std::cout << "[producer] push " << i << std::endl;
        usleep(100000);  // 0.1 秒
    }
}

void consumer(RingQueue<int>& rq, int id)
{
    int val;
    while (true)
    {
        rq.Pop(&val);
        std::cout << "[consumer-" << id << "] pop " << val << std::endl;
        usleep(200000);  // 0.2 秒
    }
}

int main()
{
    const size_t CAP = 8;
    RingQueue<int> rq(CAP);

    std::thread prod(producer, std::ref(rq), 20);  // 生产 20 个

    std::vector<std::thread> cons;
    for (int i = 0; i < 3; ++i)
        cons.emplace_back(consumer, std::ref(rq), i);

    prod.join();
    for (auto& c : cons) c.join();  // 实际项目里用退出标志
    return 0;
}